import { applyMiddleware, legacy_createStore } from "redux";
import thunk from "redux-thunk";
import logger from "redux-logger"
import {ALLSTATETYPE,ALLACTIONTYPE,SETLIST,SETFOCUS} from "../type/store.d"
const initialState = {
  list: [],
  focus: []
}

const render= (state:ALLSTATETYPE = initialState, { type, payload }:ALLACTIONTYPE) => {
  switch (type) {

    case SETLIST:
      state.list=payload
    return { ...state}
    case SETFOCUS:
      const newfocusList = [...state.focus]
      if (!newfocusList.includes(payload)) {
          newfocusList.push(payload)
          state.focus = newfocusList
      }
      return { ...state }
  default:
    return state
  }
}
const store = legacy_createStore(render, applyMiddleware(thunk, logger))
export default store
